<template>
  <div class="videoAnalysisBox" v-if="videoStatus != 1">
    <div class="leftVideo" @click="handelOpenVideo"></div>
    <div class="right_pannel">
      <div class="content" ref="rightPannel" style="transition: all 2s ease" :style="{ maxHeight: expended ? 'none' : `270px` }">
        <div class="a-l_c j-c_s-b">
          <div class="comment-list">
            <span class="nums">{{ editorStore.list[2].length }} 条评论</span>
            <!-- <div class="rightSelct">
          <div
            @click="handleChangeDataSort(1)"
            :class="['left', 1 == current ? 'current' : '']"
          >
            默认
          </div>
          <div
            @click="handleChangeDataSort(2)"
            :class="['right', 2 == current ? 'current' : '']"
          >
            最新
          </div>
        </div> -->
          </div>
          <div class="searchBtn" @click="handleUpdate">去提问</div>
        </div>
        <discussBox :current="2"></discussBox>
      </div>

      <span class="load-more a-l_c" v-if="(isFlowing && editorStore.list[2].length) || expended" @click="handleExpend">
        {{ expended ? '收起' : '展开' }}所有评论
        <el-icon v-if="!expended"><ArrowDown /></el-icon>
        <el-icon v-else><ArrowUp /></el-icon>
      </span>
    </div>

    <!-- 购买视频弹窗 -->
    <CommonModal
      :type="3"
      :modelValue="showTrialModal"
      title="云帆美研视频购买须知"
      trialButtonText="先体验视频"
      :showTrialInfo="true"
      :trialCount="0"
      :fullExamCount="2"
      :showActionButtons="true"
      @trial="handleTrial"
      @purchase="handlePurchase"
      @close="handleCloseModal"
    />
  </div>
</template>
<script setup>
import CommonModal from '@/components/commModel.vue'
import { getVideoStatus } from '@/service/exam.js'
import { userEditorStore } from '@/stores/editor.js'
const editorStore = userEditorStore()
import { useExam } from '@/stores/exam.js'
const examStore = useExam()

// 视频状态
const videoStatus = ref(null)

// 检查内容是否溢出
const rightPannel = ref(null)
const isFlowing = ref(false)
const expended = ref(false)
const checkContentFlow = () => {
  if (!rightPannel.value) return

  isFlowing.value = rightPannel.value.scrollHeight > rightPannel.value.clientHeight
}
const handleExpend = () => (expended.value = !expended.value)
onMounted(() => checkContentFlow())
onUpdated(() => checkContentFlow())

const handleUpdate = () => {
  //初始化设置不同的参数信息
  editorStore.handleUpdate({ key: 'maskTitle', value: '提 问' })
  editorStore.handleUpdate({ key: 'current', value: 2 })
  editorStore.updateEditor(true)
}

// 弹窗变量
const showTrialModal = ref(false)
const handleCloseModal = () => (showTrialModal.value = false)

// 点击播放视频
const handelOpenVideo = () => {
  console.log(videoStatus.value, 'videoStatus')
  if (videoStatus.value === 0) {
    showTrialModal.value = true
    return
  }
}

const getVideoStatusFn = async () => {
  const res = await getVideoStatus({ qid: examStore.currQuestion.id })
  if (res.code == '300013') {
    console.log(res, 'videoRes')
    // 弹出弹窗 提示购买
    videoStatus.value = 0
  }else if(res.code == '300019'){
    // 视频不存在 模块隐藏
    videoStatus.value = 1
  }else if(res.code == '000000'){
    // 条件满足直接播放
    videoStatus.value = 2
  }
}

watch(
  () => examStore.currQuestion.id,
  (val) => {
    getVideoStatusFn()
    editorStore.getCommentListFn(2)
  },
  {
    immediate: true,
  }
)

import discussBox from '../discuss/discussBox.vue'
const isNeed = ref(false)
const current = ref(1)
const commitList = ref([
  {
    id: 1,
    username: '张XX',
    time: '2024-06-23 16:45',
    action: '提问',
    content: `<p>根据题干关键词whig propaganda在第二段定位。</p>`,
    replies: [
      {
        id: 2,
        username: '李XX',
        time: '2024-06-23 16:45',
        action: '回复',
        content: `<p>根据题干关键词whig propaganda在第二段定位。</p>`,
      },
    ],
    hasMore: true,
  },
])
const handleChangeDataSort = (type) => {
  current.value = type
}
</script>
<style lang="scss" scoped>
.videoAnalysisBox {
  display: flex;
  justify-content: space-between;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  margin: 20px 0px;

  .leftVideo {
    width: 480px;
    height: 300px;
    gap: 0px;
    border-radius: 8px;
    // opacity: 0px;
    background-color: #d9d9d9;
    overflow: hidden;
  }

  .load-more {
    font-family: PingFang SC;
    font-size: 14px;
    font-weight: 400;
    color: #1e8fda;
    cursor: pointer;
    margin-top: 10px;
  }

  .right_pannel {
    width: 460px;

    .content {
      overflow-y: hidden;
    }

    .searchBtn {
      width: 68px;
      background: #126983;
      border: 1px solid #126983;
      // padding: 4px 10px;
      text-align: center;
      height: 30px;
      border-radius: 8px;
      font-family: PingFang SC;
      font-size: 16px;
      font-weight: 600;
      line-height: 30px;
      // text-align: left;
      text-underline-position: from-font;
      text-decoration-skip-ink: none;
      color: #fff;
      white-space: nowrap;
      cursor: pointer;
    }

    .comment-list {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 10px;

      .nums {
        font-family: PingFang SC;
        font-size: 14px;
        font-weight: 400;
        line-height: 19.6px;
        text-align: left;
        text-underline-position: from-font;
        text-decoration-skip-ink: none;
        color: #333;
      }

      .rightSelct {
        display: flex;
        align-items: center;
        font-family: PingFang SC;
        cursor: pointer;
        font-size: 12px;
        font-weight: 400;
        line-height: 16.8px;
        text-align: left;
        text-underline-position: from-font;
        text-decoration-skip-ink: none;
        color: #ccc;
        margin: 8px 0px;

        .left {
          width: 44px;
          background-color: #ffffff;
          text-align: center;
          height: 25px;
          // padding: 4px 10px 4px 10px;
          border-radius: 8px 0px 0px 8px;
          border: 1px solid #ccc;
          // opacity: 0px;
          line-height: 25px;
          &.current {
            color: #126983;
            border: 1px solid #126983;
          }
        }

        .right {
          width: 44px;
          height: 25px;
          line-height: 25px;
          text-align: center;
          background-color: #ffffff;
          // padding: 4px 10px 4px 10px;
          border-radius: 0px 8px 8px 0px;
          border: 1px solid #ccc;
          &.current {
            color: #126983;
            border: 1px solid #126983;
          }
        }
      }
    }
  }
}
// :deep(.discussion-userInfo) {
//   margin: 0px;
// }
// :deep(.disc-header) {
//   margin-bottom: 0px !important;
// }
// :deep(.commentAction) {
//   margin: 4px 0px !important;
// }
</style>
